/*
 * network_array.cpp
 *
 *  Created on: 12.04.2012
 *      Author: delgado
 */

#include "network_array.h"

#include <cstdlib>
using std::rand;
using std::srand;
#include <ctime>
using std::time;

using std::cout; // For debugging
using std::endl;

namespace neurignacio{

Topology_Array::Topology_Array(const number_t n, const real c) : Matrix(n,n,0), n(n), c(c)
{
//	cout << "Create Topology Array of size=(" << height << "x" << width << ") with n=" << n << ", c=" << c << endl;
	// Reset the seed
	srand(time(NULL));
	for (register size_t y=0; y<height; ++y)
		for (register size_t x=0; x<width; ++x)
		{
//			cout << "\t("<< x << ", " << y << ")" << endl;
			if (x==y)
				(*this)(x,y)=0; // Not need, the cmatrix was zeroed by constructor
			else
				if (static_cast<real>(rand()) / RAND_MAX < c)
					(*this)(x,y)=1;
				else
					(*this)(x,y)=0; // Not need, the cmatrix was zeroed by constructor
		}
}

ostream& operator<<(ostream& out, const Topology_Array& topology)
{
	for (register size_t y=0; y<topology.height; ++y)
	{
		for (register size_t x=0; x<topology.width; ++x)
			out << (int)topology(x,y) << " ";
		out << endl;
	}
	return out;
}

}	// end namespace neurignacio

